package cn.itcast.quartz;

import cn.itcast.dao.cargo.ContractDao;
import cn.itcast.dao.cargo.ExportDao;
import cn.itcast.dao.system.UserDao;
import org.apache.commons.lang.time.DateUtils;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;

import java.text.SimpleDateFormat;
import java.util.*;

public class MyJob {
    @Autowired
    private UserDao userDao;
    @Autowired
    private ContractDao contractDao;
    @Autowired
    private AmqpTemplate amqpTemplate;

    //发送生日祝福
    public void sendBirEmail() {
        String bir = new SimpleDateFormat("MM-dd").format(new Date());
        List<String> emails = userDao.findEmailsByBir(bir);
        if(emails != null && emails.size() >= 1) {
            for (String email : emails) {
                amqpTemplate.convertAndSend("birEmail.send", email);
            }
        }
    }

    //发送交货提醒
    public void sendJiaoHuoEmail(){
        String format = new SimpleDateFormat("yyyy-MM-dd").format(DateUtils.addDays(new Date(), +3));
        List<String> list =contractDao.sendJiaoHuoEmailByDel(format);
        for (String email : list) {
            amqpTemplate.convertAndSend("jiaoHuoEmail.send", email);
        }
    }
}
